28.2.19 Initialization 
Perform thef ollowing procedure for initializing the SPI: 

1. Reset the SPI by clearing the RESET bit in the SPI global control register0(SPIGCR0) to 0. 
2. Take the SPI out of reset bysetting SPIGCR0.RESET to 1. 
3. ConfiguretheSPI for master or slave mode by configuring the CLKMOD and MASTER bits in the SPI global control register1(SPIGCR1). 
4. ConfiguretheSPI for3-pin,4-pinwithchipselect,4-pinwithenable,or5-pinmodebyconfiguringthe SPIpincontrol register0(SPIPC0). 
5. ChosetheSPIdataformatregistern(SPIFMTn)tobeusedbyconfiguringtheDFSELbit intheSPI transmitdataregister(SPIDAT1). Inslavemode,onlySPIFMT0issupported. 
6. ConfiguretheSPIdatarate,character length,shiftdirection,phase,polarityandotherformatoptions usingSPIFMTnselectedinstep5. 
7. IfSPImaster, thenconfigurethemasterdelayoptionsusingtheSPIdelayregister(SPIDELAY). In slavemode,SPIDELAYisnotrelevant. 
8. Select theerror interruptnotificationsbyconfiguringtheSPI interruptregister(SPIINT0)andtheSPI interrupt level register(SPILVL). 
9. EnabletheSPIcommunicationbysettingtheSPIGCR1.ENABLEto1. 
10.SetupandenabletheDMAforSPIdatahandlingandthenenabletheDMAservicingfortheSPIdata requestsbysettingtheSPIINT0.DMAREQENto1. 
11.HandleSPIdatatransferrequestsusingDMAandserviceanySPIerrorconditionsusingtheinterrupt serviceroutine.